﻿
laydate({
    elem: '#beginDate',
    format: 'YYYY-MM-DD', // 分隔符可以任意定义，该例子表示只显示年月
    festival: true, //显示节日
    max: '2100-01-01 00:00:00', //设定最小日期为当前日期
    min: '2010-01-01 00:00:00', //最大日期
    choose: function (datas) { //选择日期完毕的回调
        //alert('得到：' + datas);
    }
});

laydate({
    elem: '#endDate',
    start: laydate.now(),
    format: 'YYYY-MM-DD', // 分隔符可以任意定义，该例子表示只显示年月
    festival: true, //显示节日
    max: '2100-01-01 00:00:00', //设定最小日期为当前日期
    min: '2010-01-01 00:00:00', //最大日期
    choose: function (datas) { //选择日期完毕的回调
        //alert('得到：' + datas);
    }
});

function selectDate(day) {
    var mydate = new Date();
    var endDate = "" + mydate.getFullYear() + "-";
    endDate += (mydate.getMonth() + 1) + "-";
    endDate += mydate.getDate();
    $("#endDate").val(endDate);

    if (day == -1) {
        mydate.setYear(mydate.getFullYear() - 20);
    } else {
        mydate.setDate(mydate.getDate() - day);
    }

    var beginDate = "" + mydate.getFullYear() + "-";
    beginDate += (mydate.getMonth() + 1) + "-";
    beginDate += mydate.getDate();
    $("#beginDate").val(beginDate);
}

//选择楼盘
function GoToLayer() {

    parent.layer.open({
        type: 2,
        title: '选择中介',
        shadeClose: false,
        shade: 0.4,
        area: ['1000px', '850px'],
        content: '/Runnings/Runnings/BuildingsIndex',
        end: function () {
            //获取子窗口返回值     
            $('#buildName').val(parent.buildName);
            $('#buildID').val(parent.buildID);
        }
    });
}

var $table = $("#table");

$("#mainForm").submit(function () {
    $table.bootstrapTable('refresh');
    return false;
});


$(function () {

    //1.初始化Table

    var table_columns = [
        {
            width: 38,
            field: 'selected',
            checkbox: true,
        },
        {
            width: 300,
            field: 'id',
            title: '流水编号',
            align: 'center'
        }, {
            width: 300,
            field: 'userName',
            title: '经纪人',
            align: 'center'
        }, {
            width: 300,
            field: 'userPhone',
            title: '经纪人电话',
            align: 'center'
        }, {
            width: 900,
            field: 'customerName',
            title: '客&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;户',
            align: 'left',
            formatter: function (value, row, index) {
                var temp = '';
                if (isAuthority('144')) {
                    temp += [
                    '<a class="customername" href="javascript:void(0)" title="修改客户">',
                    '<i class="glyphicon glyphicon-edit"></i>',
                    '</a>  '].join('');
                }

                temp += [
                    '<label>',
                    value,
                    '</label>'
                ].join('');

                return temp;
            },
            events: operateEvents
        },
        {
            width: 300,
            field: 'customerPhone',
            title: '客&nbsp;&nbsp;户&nbsp;&nbsp;电&nbsp;&nbsp;话',
            align: 'center',
            formatter: function (value, row, index) {
                var temp = '';
                if (isAuthority('145')) {
                    temp += [
                    '<a class="customerphone" href="javascript:void(0)" title="修改电话">',
                    '<i class="glyphicon glyphicon-edit"></i>',
                    '</a>  '].join('');
                }

                temp += [
                    '<label>',
                    value,
                    '</label>'
                ].join('');

                return temp;
            },
            events: operateEvents
        },
        {
            width: 300,
            field: 'propertyConsultantName',
            title: '置&nbsp;业&nbsp;顾&nbsp;问',
            align: 'left',
            formatter: function (value, row, index) {
                return [
                    '<a class="consult" href="javascript:void(0)" title="修改置业顾问">',
                    '<i class="glyphicon glyphicon-edit"></i>',
                    '</a>  ',
                    '<label>',
                    value,
                    '</label>'
                ].join('');
            },
            events: operateEvents
        },
        {
            width: 300,
            field: 'starTarget',
            title: '星标',
            align: 'center',
            formatter: function (value, row, index) {

                if (value == 0) {
                    var str = "无";
                    return [
                  '<a class="kv-file-zoom btn btn-xs btn-default" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
                  '<i">' + str + '</i>',
                  '</a>  '
                    ].join('');
                }
                else if (value == 1) {
                    var str = "客户信用不良";
                    return [
                  '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
                  '<i">' + str + '</i>',
                  '</a>  '
                    ].join('');
                }
                else if (value == 2) {
                    var str = "客户首付分期";
                    return [
                  '<a class="kv-file-zoom btn btn-xs btn-default" style="background-color: #55a2ed;" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
                  '<i">' + str + '</i>',
                  '</a>  '
                    ].join('');
                }
                else if (value == 3) {
                    var str = "客户全款购买";
                    return [
                  '<a class="kv-file-zoom btn btn-xs btn-danger" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
                  '<i">' + str + '</i>',
                  '</a>  '
                    ].join('');
                }
                else if (value == 4) {
                    var str = "别墅洋房";
                    return [
                  '<a class="kv-file-zoom btn btn-xs btn-success" style="background-color: #dc5fce;" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
                  '<i">' + str + '</i>',
                  '</a>  '
                    ].join('');
                }
                else if (value == 5) {
                    var str = "其他";
                    return [
                  '<a class="kv-file-zoom btn btn-xs btn-warning" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
                  '<i">' + str + '</i>',
                  '</a>  '
                    ].join('');
                }
                else {
                    var str = "无";
                    return [
                  '<a class="kv-file-zoom btn btn-xs btn-default" href="javascript:void(0)"  onclick="starTargetSet(' + value + ',' + row.id + ')">',
                  '<i">' + str + '</i>',
                  '</a>  '
                    ].join('');
                }
            }
        },
        {
            width: 300,
            field: 'intermediaryName',
            title: '门&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;店',
            align: 'center'
        },
        {
            width: 300,
            field: 'sellStaff',
            title: '销&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;售',
            align: 'center'
        }, {
            width: 300,
            field: 'filingTime',
            title: '报&nbsp;&nbsp;备&nbsp;&nbsp;时&nbsp;&nbsp;间',
            align: 'center'
        },
        {
            width: 900,
            field: 'bandSawTime',
            title: '带&nbsp;&nbsp;看&nbsp;&nbsp;时&nbsp;&nbsp;间',
            align: 'center'
        },
        {
            field: 'subscribeTime',
            title: '认&nbsp;&nbsp;购&nbsp;&nbsp;时&nbsp;&nbsp;间',
            align: 'left'
        },
        {
            width: 300,
            field: 'customerState',
            title: '客户状态',
            align: 'center'
        },
        {
            width: 300,
            field: 'sawPicId',
            title: '带看单图片',
            align: 'center',
            formatter: function (value, row, index) {
                if (parseInt(row['bandSawPicCount'])==0) {
                    return [
                    '<a class="sawpic" href="javascript:void(0)" title="带看单图片">',
                    '<i class="glyphicon glyphicon-upload"></i>',
                    '</a>  '
                    ].join('');
                } else {
                    return [
                    '<a class="sawpic" href="javascript:void(0)" title="带看单图片">',
                    '<i class="glyphicon glyphicon-picture"></i>',
                    '×' + row['bandSawPicCount'],
                    '</a>  '
                    ].join('');
                }
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'subPicId',
            title: '成交单图片',
            align: 'center',
            formatter: function (value, row, index) {
                if (parseInt(row['completePicCount']) == 0) {
                    return [
                    '<a class="subpic" href="javascript:void(0)" title="成交单图片">',
                    '<i class="glyphicon glyphicon-upload"></i>',
                    '</a>  '
                    ].join('');
                } else {
                    return [
                    '<a class="subpic" href="javascript:void(0)" title="成交单图片">',
                    '<i class="glyphicon glyphicon-picture"></i>',
                    '×' + row['completePicCount'],
                    '</a>  '
                    ].join('');
                }                
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'recordPicId',
            title: '备案合同',
            align: 'center',
            formatter: function (value, row, index) {
                if (parseInt(row['recordPicCount']) == 0) {
                    return [
                    '<a class="recordpic" href="javascript:void(0)" title="备案合同">',
                    '<i class="glyphicon glyphicon-upload"></i>',
                    '</a>  '
                    ].join('');
                } else {
                    return [
                    '<a class="recordpic" href="javascript:void(0)" title="备案合同">',
                    '<i class="glyphicon glyphicon-picture"></i>',
                    '×' + row['recordPicCount'],
                    '</a>  '
                    ].join('');
                }                
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'buildingName',
            title: '楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;盘',
            align: 'center'
        }
        , {
            width: 300,
            field: 'area',
            title: '面积',
            align: 'center',
            formatter: function (value, row, index) {
                return value + "平";
            }
        }, {
            width: 300,
            field: 'address',
            title: '门牌号',
            align: 'left',
            formatter: function (value, row, index) {
                var temp = '';
                if (isAuthority('146')) {
                    temp += [
                    '<a class="address" href="javascript:void(0)" title="修改门牌号">',
                    '<i class="glyphicon glyphicon-edit"></i>',
                    '</a>  '].join('');
                }

                temp += [
                    '<label>',
                    value,
                    '</label>'
                ].join('');

                return temp;
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'bargainMoney',
            title: '订金',
            align: 'center',
            formatter: function (value, row, index) {
                return value + "元";
            }
        }, {
            width: 300,
            field: 'downPaymentMoney',
            title: '首付',
            align: 'center',
            formatter: function (value, row, index) {
                return value + "元";
            }
        }, {
            width: 300,
            field: 'totalPrice',
            title: '全款',
            align: 'center',
            formatter: function (value, row, index) {
                return value + "元";
            }
        }, {
            width: 300,
            field: 'brokerage',
            title: '门店佣金',
            align: 'center',
            formatter: function (value, row, index) {
                return value + "元";
            }
        }, {
            width: 300,
            field: 'remark',
            title: '备注',
            align: 'left',
            formatter: function (value, row, index) {
                var temp = '';
                if (isAuthority('147')) {
                    temp += [
                    '<a class="remark" href="javascript:void(0)" title="修改备注">',
                    '<i class="glyphicon glyphicon-edit"></i>',
                    '</a>  '].join('');
                }

                temp += [
                    '<label>',
                    value,
                    '</label>'
                ].join('');

                return temp;
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'operName',
            title: '操作员',
            align: 'center',
            formatter: function (value, row, index) {
                return [
                    '<a class="opers" href="javascript:void(0)" title="查看操作员">',
                    '操作员',
                    '</a>  '
                ].join('');
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'cancelId',
            title: '取&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;消',
            align: 'center',
            formatter: function (value, row, index) {
                var txt = "";
                var temp = '';

                if (state == 2) {
                    txt = '取消报备';
                    if (isAuthority('149')) {
                        temp += [
                        '<a class="cancel" href="javascript:void(0)" title="取消">',
                            txt,
                        '</a>  '
                        ].join('');
                    }
                } else if (state == 5 || state == 6 || state == 7 || state == 8) {
                    txt = '取消订单';
                    if (isAuthority('156')) {
                        temp += [
                        '<a class="cancel" href="javascript:void(0)" title="取消">',
                            txt,
                        '</a>  '
                        ].join('');
                    }
                }

                return temp;
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'priceId',
            title: '填写房款',
            align: 'center',
            formatter: function (value, row, index) {
                var temp = '';

                if (isAuthority('152')) {
                    temp += [
                    '<a class="price" href="javascript:void(0)" title="填写房款">',
                    '填写房款',
                    '</a>  '
                    ].join('');
                }

                return temp;
            },
            events: operateEvents
        }, {
            width: 300,
            field: 'operId',
            title: '操&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;作',
            align: 'center',
            formatter: function (value, row, index) {
                var txt = '';
                var temp = '';
                
                switch (state) {
                    case 1://报备待审
                        txt = '报备审批';
                        if (isAuthority('148')) {
                            temp += [
                                '<a class="oper" href="javascript:void(0)" title="操作">',
                                txt,
                                '</a>  '
                            ].join('');
                        }
                        break;
                    case 2://报备通过
                        txt = '带看确认';
                        if (isAuthority('150')) {
                            temp += [
                                '<a class="oper" href="javascript:void(0)" title="操作">',
                                txt,
                                '</a>  '
                            ].join('');
                        }
                        break;
                    case 4://已带看
                        txt = '订金确认';
                        if (isAuthority('151')) {
                            temp += [
                                '<a class="oper" href="javascript:void(0)" title="操作">',
                                txt,
                                '</a>  '
                            ].join('');
                        }
                        break;
                    case 5://已交订金
                        txt = '首付款确认';
                        if (isAuthority('153')) {
                            if (parseInt(row['buildingsBrokerageGroupID']) > 0) {

                                //已填写房款，佣金分组ID>0
                                temp += [
                                '<a class="oper" href="javascript:void(0)" title="操作">',
                                txt,
                                '</a>  '
                                ].join('');
                            } else {

                                //没有填写房款，佣金分组ID=0
                                temp += [
                                '未填写房款'
                                ].join('');
                            }
                            
                        }
                        break;
                    case 6://已付首款
                        txt = '备案确认';
                        if (isAuthority('154')) {
                            temp += [
                                '<a class="oper" href="javascript:void(0)" title="操作">',
                                txt,
                                '</a>  '
                            ].join('');
                        }
                        break;
                    case 7://已备案
                        txt = '完成确认';
                        if (isAuthority('155')) {
                            temp += [
                                '<a class="oper" href="javascript:void(0)" title="操作">',
                                txt,
                                '</a>  '
                            ].join('');
                        }
                        break;
                    case 3://失败完成
                    case 10:
                    case 8://已完成
                        txt = '';
                        break;
                    case 9://退房待审
                        txt = '退房审核';
                        if (isAuthority('157')) {
                            temp += [
                                '<a class="oper" href="javascript:void(0)" title="操作">',
                                txt,
                                '</a>  '
                            ].join('');
                        }
                        break;
                    default:
                        break;
                }

                return temp;
            },
            events: operateEvents
        }
    ];

    var orderBy = "";
    var table_queryParams = function (params) {
        var data = {};
        if (parent.CustomerSource_Index_data != undefined) {
            data = parent.CustomerSource_Index_data;
        } else {
            data = $("#mainForm").formToJson(false);
        }
        parent.CustomerSource_Index_data = undefined;
        data.pageIndex = (params.offset / params.limit) + 1;
        data.pageSize = params.limit;
        //data.orderBy = this.sortName;
        //data.orderByType = this.sortOrder;
        data.beginDate = $('#beginDate').val();
        data.endDate = $('#endDate').val();
        data.state = state;    //状态

        return data;

        //var temp = {
        //    pageSize: params.limit,                             //行数
        //    pageIndex: (params.offset / params.limit) + 1,      //页码
        //    state: state,    //状态
        //    search: $("#mainForm").formToJson(false),
        //    //Province: $('#Province').val(),
        //    //City: $('#City').val(),
        //    //District: $('#District').val(),
        //    //WhetherOnline: $('#WhetherOnline').val(),
        //    //PropertyType: $('#PropertyType').val(),
        //};
        ////console.info(temp);
        //return temp;
    };

    //$table.initTable("/Runnings/Runnings/IndexAsync", table_columns, 180, table_queryParams);

    $table.bootstrapTable({
        url: '/Runnings/Runnings/IndexAsync',            //数据来源地址
        method: 'post',                     //数据请求方式
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否启用分页
        sidePagination: 'server',           //在服务器端分页
        queryParams: table_queryParams,           //传递参数
        pageNumber: 1,                      //初始化加载第一页，默认第一页
        pageSize: 20,                       //每页的记录行数（*）
        pageList: [10, 20, 30, 40, 50, 'All'],     //可供选择的每页的行数（*）
        clickToSelect: true,                //是否启用点击选中行
        toolbar: "#tableToolBar",
        height: getHeight(),
        //search: true,
        showRefresh: true,
        showColumns: true,
        showExport: true,                     //是否显示导出
        exportDataType: "basic",              //basic', 'all', 'selected'.
        exportTypes: ['excel'],
        exportOptions: { fileName: '新房报备列表' },
        toolbar: '#exampleToolbar',
        iconSize: 'outline',
        icons: {
            refresh: 'glyphicon-repeat',
            columns: 'glyphicon-list'
        },
        columns: table_columns
        
    });

    //默认隐藏
    $table.bootstrapTable('hideColumn', 'cancelId');
    $table.bootstrapTable('hideColumn', 'priceId');
    $table.bootstrapTable('hideColumn', 'operId');

    if (state == 2 || state == 5 || state == 6 || state == 7 || state == 8) {
        $table.bootstrapTable('showColumn', 'cancelId');//取消 列
    }
    if (state == 5 || state == 3 || state == 10) {
        $table.bootstrapTable('showColumn', 'priceId');//填写房款 列
    }
    if (state == 1 || state == 2 || state == 4 || state == 5 || state == 6 || state == 9) {
        $table.bootstrapTable('showColumn', 'operId');//操作 列
    }

});

//获取表格高度
function getHeight() {
    return $(window).height() - 150;
}

//刷新表格数据
var refreshTable = function () {
    $table.bootstrapTable('refresh');
}

//近3天
$('#dateSel01').click(function () {
    $('#setBtn').click();
    $('#beginDate').val(laydate.now(-2));
    $('#endDate').val(laydate.now(0));
    $table.bootstrapTable('refresh');
});
//近7天
$('#dateSel02').click(function () {
    $('#setBtn').click();
    $('#beginDate').val(laydate.now(-6));
    $('#endDate').val(laydate.now(0));
    $table.bootstrapTable('refresh');
});
//本月
$('#dateSel03').click(function () {
    $('#setBtn').click();
    $("#beginDate").val(TimeObjectUtil.getMonthDateTime(0).startTime);
    $("#endDate").val(TimeObjectUtil.getMonthDateTime(0).endTime);
    $table.bootstrapTable('refresh');
});
//上个月
$('#dateSel04').click(function () {
    $('#setBtn').click();
    $("#beginDate").val(TimeObjectUtil.getMonthDateTime(-1).startTime);
    $("#endDate").val(TimeObjectUtil.getMonthDateTime(-1).endTime);
    $table.bootstrapTable('refresh');
});

//自定义列事件
window.operateEvents = {

    'click .customername': function (e, value, row, index) {
        customerNameEdit(row['id']);//客户姓名
    },
    'click .customerphone': function (e, value, row, index) {
        customerPhoneEdit(row['id']);//客户电话
    },
    'click .consult': function (e, value, row, index) {
        consultEdit(row['id']);//置业顾问
    },
    'click .address': function (e, value, row, index) {
        addressEdit(row['id']);//门牌号
    },
    'click .remark': function (e, value, row, index) {
        remarkEdit(row['id']);//备注
    },
    'click .opers': function (e, value, row, index) {
        operList(row['id']);//操作员
    },

    'click .sawpic': function (e, value, row, index) {
        sawPic(row['id']);//带看单图片
    },
    'click .subpic': function (e, value, row, index) {
        subPic(row['id']);//成交单图片
    },
    'click .recordpic': function (e, value, row, index) {
        recordPic(row['id']);//备案合同
    },

    'click .cancel': function (e, value, row, index) {
        cancelFunc(row['id']);//取消
    },
    'click .price': function (e, value, row, index) {
        priceFunc(row['id']);//填写房款
    },
    'click .oper': function (e, value, row, index) {
        operFunc(row['id']);//操作
    }
};

//客户姓名
function customerNameEdit(id) {
    parent.layer.open({
        type: 2,
        title: '修改客户姓名',
        shadeClose: true,
        shade: 0.4,
        area: ['520px', '200px'],
        content: '/Runnings/Runnings/CustomerNameEdit?id=' + id,
        end: function () {
            refreshTable();
        }
    });
}

//客户电话
function customerPhoneEdit(id) {
    parent.layer.open({
        type: 2,
        title: '修改客户电话',
        shadeClose: true,
        shade: 0.4,
        area: ['520px', '200px'],
        content: '/Runnings/Runnings/CustomerPhoneEdit?id=' + id,
        end: function () {
            refreshTable();
        }
    });
}

//星标标设置
function starTargetSet(value, id) {
    parent.layer.open({
        type: 2,
        title: "星标类型",
        shadeClose: false,
        shade: 0.4,
        area: ["800px", "260px"],
        content: "/Runnings/Runnings/SetStarTarget?id=" + id,
        end: function () {
            refreshTable();
        }
    });
}

//置业顾问
function consultEdit(id) {
    parent.layer.open({
        type: 2,
        title: '修改置业顾问',
        shadeClose: true,
        shade: 0.4,
        area: ['520px', '200px'],
        content: '/Runnings/Runnings/ConsultEdit?id=' + id,
        end: function () {
            refreshTable();
        }
    });
}

//门牌号
function addressEdit(id) {
    parent.layer.open({
        type: 2,
        title: '修改门牌号',
        shadeClose: true,
        shade: 0.4,
        area: ['520px', '200px'],
        content: '/Runnings/Runnings/AddressEdit?id=' + id,
        end: function () {
            refreshTable();
        }
    });
}

//备注
function remarkEdit(id) {
    parent.layer.open({
        type: 2,
        title: '修改备注',
        shadeClose: true,
        shade: 0.4,
        area: ['520px', '200px'],
        content: '/Runnings/Runnings/RemarkEdit?id=' + id,
        end: function () {
            refreshTable();
        }
    });
}

//操作员
function operList(id) {
    parent.layer.open({
        type: 2,
        title: '查看操作员',
        shadeClose: true,
        shade: 0.4,
        area: ['540px', '650px'],
        content: '/Runnings/Runnings/OperList?id=' + id,
        end: function () {
            //refreshTable();
        }
    });
}

//带看单图片
function sawPic(id) {
    parent.layer.open({
        type: 2,
        title: '带看单图片',
        shadeClose: true,
        shade: 0.4,
        area: ['600px', '550px'],
        content: '/Images/Index?GroupID=3&InterfixID=' + id + '&ImageType=1',
        end: function () {
            refreshTable();
        }
    });
}

//成交单图片
function subPic(id) {
    parent.layer.open({
        type: 2,
        title: '成交单图片',
        shadeClose: true,
        shade: 0.4,
        area: ['600px', '550px'],
        content: '/Images/Index?GroupID=3&InterfixID=' + id + '&ImageType=2',
        end: function () {
            refreshTable();
        }
    });
}

//备案合同
function recordPic(id) {
    parent.layer.open({
        type: 2,
        title: '备案合同',
        shadeClose: true,
        shade: 0.4,
        area: ['600px', '550px'],
        content: '/Images/Index?GroupID=3&InterfixID=' + id + '&ImageType=3',
        end: function () {
            refreshTable();
        }
    });
}

//取消
function cancelFunc(id) {
    layer.confirm('您确定要取消吗?', {
        btn: ['是的', '取消'] //按钮
    }, function () {
        $.ajax({
            url: "/Runnings/Runnings/CancelAsync",
            type: "post",
            dataType: "json",
            data: {
                id: id
            },
            success: function (data) {
                //Info,Success,Warning,Error
                var type = data.type;
                if (type == 1) {
                    layer.msg(data.content,
                {
                    icon: 6, time: 2000
                },
                        function () {
                            refreshTable();
                        });
                } else {
                    layer.msg(data.content, {
                        icon: 5, time: 2000
                    });
                }
            }
        });
    }, function () {
        return;
    });
}

//填写房款
function priceFunc(id) {
    parent.layer.open({
        type: 2,
        title: '房款操作',
        shadeClose: false,
        shade: 0.4,
        area: ['520px', '450px'],
        content: '/Runnings/Runnings/PriceIndex?id=' +id,
        end: function () {
            refreshTable();
        }
    });
}

//操作
function operFunc(id) {

    var width = '520px';
    var height = '250px';
    if (state == 4) {
        height = '330px';
    }
    if (state == 5) {
        height = '200px';
    }

    if (state == 1 || state == 4 || state == 5 || state == 9) {
        parent.layer.open({
            type: 2,
            title: '操作',
            shadeClose: false,
            shade: 0.4,
            area: [width, height],
            content: '/Runnings/Runnings/OperIndex?id=' + id + '&state=' + state,
            end: function () {
                refreshTable();
            }
        });
    } else {
        var txt = '';
        switch (state) {
            case 2:
                txt = '已带看';
                break;
            case 6:
                txt = '已备案';
                break;
            case 7:
                txt = '已完成';
                break;
            default:
                break;
        }

        layer.confirm('您确定'+txt+'吗?', {
            btn: ['是的', '取消'] //按钮
        }, function () {
            $.ajax({
                url: "/Runnings/Runnings/OperAsync",
                type: "post",
                dataType: "json",
                data: {
                    id: id
                },
                success: function (data) {
                    //Info,Success,Warning,Error
                    var type = data.type;
                    if (type == 1) {
                        layer.msg(data.content,
                    {
                        icon: 6, time: 2000
                    },
                            function () {
                                refreshTable();
                            });
                    } else {
                        layer.msg(data.content, {
                            icon: 5, time: 2000
                        });
                    }
                }
            });
        }, function () {
            return;
        });
    }
    
}